<?php
namespace app\common\model\logic;

use think\Model;

class CarOrderModel extends Model {

    protected $name = 'car_order'; //定义栏目表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = true;
    //类型自动转换
    protected $type = [
        'order_start_time'=>'timestamp:Y-m-d H:i:s',
        'order_end_time'=>'timestamp:Y-m-d H:i:s',
        'back_time'=>'timestamp:Y-m-d H:i:s',
        'order_start_mm'=>'integer',
        'order_end_mm'=>'integer',
        'order_mileage'=>'integer',
        'order_charge'=>'float',
        'order_advance'=>'float',
        'btype_id'=>'integer',
        'sort'=>'integer'
    ];
    public function getCarStatusTextAttr($value, $data)
    {
        $arr=['1'=>'出车','2'=>'收车'];
        return $arr[$data['car_status']];
    }
    public function getIsPushTextAttr($value, $data)
    {
        $arr=['1'=>'否','2'=>'是'];
        return $arr[$data['is_push']];
    }


    /**
     * 获取检索条件
     * @param $query
     */
    public function getExtendMap($query){
        return [];
    }

    //读取单条数据
    public function read($aid){
        try{
            $info = $this->get($aid)->toArray();
            return $info;
        } catch (\Exception $e){
            exception($e->getMessage(),40001);
        }
    }
    
    //格式化列表
    public function formatList($list){
        return $list;
    }
    //格式化单条内容
    public function formatInfo($info){
        return $info;
    }
    
    //添加数据
    public function add($data){
        try{
            $this->isUpdate(false)->allowField(true)->save($data);
            return true;
        }catch (\Exception $e){
            exception($e->getMessage(),40001);
        }
    }
    //修改数据
    public function edit($data){
        try{

            $this->isUpdate(true)->allowField(true)->save($data);
            return true;
        } catch (\Exception $e){
            exception($e->getMessage(),40001);
        }
    }
    //删除数据
    public function del($aid){
        try{
            $this->destroy($aid);
            return true;
        } catch (\Exception $e){
            exception($e->getMessage(),40001);
        }
    }
}